<template>
  <div>
    <el-form :inline="true" :model="emp" class="demo-form-inline">
      <el-form-item label="搜索内容">
        <el-input v-model="emp.content" placeholder="请输入搜索条件"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="empList"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="id">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="age"
        label="年龄">
      </el-table-column>
      <el-table-column
        prop="bir"
        label="生日">
      </el-table-column>
      <el-table-column
        prop="content"
        label="简介" width="800">
        <template slot-scope="scope">
          <p v-html="scope.row.content"></p>
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="address"
        label="操作" width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="toUpdate(scope.row)">编辑</el-button>
          <el-button type="danger" size="mini" @click="deleteEmp(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
    export default {
        name: "empList",
      data(){
        return {
          empList:[],
          emp:{}
        }
      },
      methods:{
        deleteEmp(id){
          this.axios({
            url:"/emps/"+id,
            method:"DELETE"
          }).then(
            (resp)=>{
              this.$message("删除成功！");
              this.selectAll();
            }
          );
        },
        selectAll(){
          this.axios({
            url:"/emps",
            method:"GET"
          }).then(
            (resp)=>{
              this.empList=resp.data;
            }
          );
        },
        toUpdate(emp){
          this.$router.push({path:"/updateEmp",query:{emp:emp}});
        },
        onSubmit(){
          this.axios({
            url:"/emps/content/"+this.emp.content,
            method:"GET"
          }).then(
            (resp)=>{
              this.empList=resp.data;
            }
          );
        }
      },
      created(){
        this.selectAll();
      }
    }
</script>

<style scoped>

</style>
